<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>如何查找当前字符的所有位置</title>
    
</head>
<body>
    <script type="text/javascript">
        var str = 'He unfolded the map and set it on the floor.';
        // 查找e在str中的所有的位置
        var arr = [];
        var pos = str.indexOf('e')
        while(pos>-1){
            // 找到当前e字符对应的位置
            arr.push(pos);
            pos = str.indexOf('e', pos+1);
        }
        console.log(arr);
        arr.forEach(function(item,index){
            console.log(item);
            console.log(str[item]);
        });
    </script>
</body>
</html>